/*
 * BPlusTree.h
 *
 *  Created on: 08/11/2013
 *      Author: gastonmontes
 */

#ifndef BPLUSTREE_H_
#define BPLUSTREE_H_

#include "../blockManagment/FreeSpaceFile.h"
#include "../BlockPersistor.h"
#include "../BlockFile.h"
#include "BPlusNode.h"

#define SECFILE_EXT ".dat"
#define FREESPACE_EXT ".fsm"

template <class T>
class BPlusTree {

private:
	BlockFile blocksFile;
	FreeSpaceFile freeSpaceFile;
	BigInt currentBlockIndex;

	String path;
	BigInt blockSize;
	float capacity;

	BPlusNode<T> rootNode;
	BPlusNode<T> currentNode;

public:
	// Constructor.
	BPlusTree(const String& _path, BigInt _blockSize);

	// Destructor.
	virtual ~BPlusTree();

private:
	bool open(const String& path, bool create = false);
	void create(const String& path);
	void close();

	// This method read the next block in currentNode.
	bool readBlock(BigInt index);

	// This method add a NodeBlock to the blocksFile.
	void addBlock(const BPlusNode<T>& block);
};

#endif /* BPLUSTREE_H_ */
